import { Button } from 'antd';
import { withRouter } from 'react-router'
import { connect } from 'react-redux';

class AuthButton extends React.Component {

    getThisPathList = () => {
        //获得当前页面菜单的按钮组
        const authMenuList = this.props.authMenuList;
        for (var i = 0; i < authMenuList.length; i++) {
            if (authMenuList[i].path == this.props.match.path) {
                return authMenuList[i].btnChild;
            }
        }
        return [];
    }

    render() {
        // 处理权限
        let isShow = false;
        const btnChildList = this.getThisPathList();
        for (var j = 0; j < btnChildList.length; j++) {
            if (btnChildList[j].authName == this.props.authName) {
                isShow = true;
                break;
            }
        }
        if (isShow) {
            return <Button {...this.props}>{this.props.children}</Button>
        } else {
            return null
        }
    }
}

const mapStateToProps = state => {
    return {
        authMenuList: state.authMenuList
    }
}

export default withRouter(connect(mapStateToProps)(AuthButton))